<?php
class Geocode {

	public $cachePath = "./cache/location/";
	private $sxml;
	private $coord;
	
	function Geocode($name) {
		$name = strtolower($name);
		$name = urlencode($name);
		$file = $this->cachePath.$name.".xml";
        if (@fopen($file, "r")) {
            $xml = file_get_contents($file);
            $this->sxml = new SimpleXMLElement(utf8_encode($xml));
        } else {
            $xml = file_get_contents("http://maps.google.com/maps/geo?q=".$name."&output=xml&sensor=false&key=ABQIAAAAOyTV-UG0inMugD3qV8e-dxQ66ILPtjiMtvBruV6EvDOx2TtZ-hSljX1JfzWyUC86VTH2-HJtAkpQNg"); 
            $fp = @fopen($file, "w");
            if($fp) {
               $result = fwrite($fp, $xml);
               fclose($fp);
            }
            $this->sxml = new SimpleXMLElement(utf8_encode($xml));
        }
        $this->coord = explode(",",(string)$this->sxml->Response->Placemark->Point->coordinates);
	}

    function getLong() {
        return $this->coord[0];
    }   
    
    function getLat() {
        return $this->coord[1];
    }   
}
?>